
from random import randint


#~ from helpers import *
#~ __print_category('FUNCTIONS')
def __rand_questions(fun, args_intervals, how_many):
    __print_category(fun.__name__+'_RANDOM')
    for i in range(how_many):
        args  = [randint(*interval) for interval in args_intervals]
        fun( *args )
        
def __print_category(cat_name, sub_path='TESTAI/Funkcijos/Unary_Arithmetic'):
    print("\n$CATEGORY: $system$/%s/%s\n" % (sub_path, cat_name))


##########  unary arithmetic returns ##########


def funCalls_print_inside_G_FGF(_a=-3, _k=10):
    """Ką atspausdins? (atskirkite tarpais)"""
    def abra(x):
        return x*2

    def kad(y):
        print (y)
        return y+_k

    abra( kad( abra (_a) ) )
__rand_questions(funCalls_print_inside_G_FGF, [(-3, 9), (-3, 9)], 5 )


def funCalls_print_inside_both_FGF(_a=-3, _k=10):
    """Ką atspausdins? (atskirkite tarpais)"""
    def abra(x):
        print( x )
        return x*2

    def kad(y):
        print (y)
        return y+_k

    abra( kad( abra (_a) ) )  
__rand_questions(funCalls_print_inside_both_FGF, [(-3, 9), (-3, 9)], 5 )


def funCalls_FGF(_a=-3, _k=10):
    """Ką atspausdins?"""
    def abra(x):
        return x*3

    def kad(y):
        return y+_k

    print( abra( kad( abra (_a) ) )  )
__rand_questions(funCalls_FGF, [(-3, 9), (-3, 9)], 5 )


def funCalls_FG(_a=-3, _k=10):
    """Ką atspausdins?"""
    def abra(x):
        return x*5

    def kad(y):
        return y+_k

    print(  kad( abra (_a) ) )  
__rand_questions(funCalls_FG, [(-3, 9), (-3, 9)], 5 )
        

def funCalls_unreached_print_inside_FG(_a=-3, _k=10):
    """Ką atspausdins? (atskirkite tarpais)"""
    def abra(x):
        return x*2

    def kad(y):
        return y+_k
        print (y)

    print( kad( abra (_a) ) )
__rand_questions(funCalls_unreached_print_inside_FG, [(-3, 9), (-3, 9)], 5 )




def __print_category(cat_name, sub_path='TESTAI/Funkcijos/Binary_arithmetic'):
    print("\n$CATEGORY: $system$/%s/%s\n" % (sub_path, cat_name))

############ binary arguments ######
def funCalls_FG_2(_a=-3, _b=2, _k=10):
    """Ką atspausdins? (atskirkite tarpais)"""
    def abra(x, y):
        return x*y

    def kad(y):
        return y+_k


    print( kad( abra (_a, _b) ) )
__rand_questions(funCalls_FG_2, [(-3, 9), (-3, 9), (-3, 9)], 5 )



def funCalls_print_inside_G_FGF_2(_a=-3, _b=2, _k=10):
    """Ką atspausdins? (atskirkite tarpais)"""
    def abra(x, y):
        return x*y

    def kad(y):
        print (y)
        return y+_k

    print( abra( _b,  kad( abra (_a, _b+1) ) ) )
__rand_questions(funCalls_print_inside_G_FGF_2, [(-3, 9), (-3, 9), (-3, 9)], 5 )


def funCalls_FGF_2(_a=-3, _b=2, _k=10):
    """Ką atspausdins?"""
    def abra(x, z):
        return x*z

    def kad(y):
        return y+_k

    print( abra( _a, kad( abra (_a, _b) ) )  )
__rand_questions(funCalls_FGF_2, [(-3, 9), (-3, 9), (-3, 9)], 5 )

######## Various ##############
def __print_category(cat_name, sub_path='TESTAI/Funkcijos/Various'):
    print("\n$CATEGORY: $system$/%s/%s\n" % (sub_path, cat_name))



##########  if/else returns ##########


def fun_ifs_stacked(_a=8, _b=7, _min=4):
    """Ką atspausdins?"""

    def stipendija(x, riba):
        if x < _min:
            return -100
        if x >= riba:
            return 50*x
        return 0

    print( stipendija(_a, _b) )
    
__rand_questions(fun_ifs_stacked, [(2, 10), (2, 9), (0, 8)], 5 )

__print_category('fun_loops_FIXED')
###### loops in functions ##########
######### loop sum ########
def fun_loop_sum_print_inside(_sar=[8, 5, 2]):
    """Ką atspausdins?"""

    def sumuojam( sar ):
        suma = 0
        for x in sar:
            suma = suma+x
            print ( suma )

        return suma

    print( sumuojam(_sar) )
fun_loop_sum_print_inside()


def fun_loop_sum_early_return(_sar=[7, 2, 3]):
    """Ką atspausdins?"""

    def sumuojam( sar ):
        suma = 0
        for x in sar:
            suma = suma+x
            return suma

    print( sumuojam(_sar) )
fun_loop_sum_early_return()

def fun_loop_sum(_sar=[-7, 2, 3]):
    """Ką atspausdins?"""

    def sumuojam( sar ):
        suma = 0
        for x in sar:
            suma = suma+x
        return suma

    print( sumuojam(_sar) )
fun_loop_sum()

def fun_loop_sum__avg(_sar=[10, 2, 3]):
    """Ką atspausdins?"""

    def sumuojam( sar ):
        suma = 0
        for x in sar:
            suma = suma+x
        return suma

    sar = _sar
    vid = sumuojam(sar) / len(sar)
    print(vid)    
fun_loop_sum__avg()

####### loop filters #####

def fun_loop_print_filter_remainder(_sar=[9, 2, 3, 12, 10], _dalmuo=3):
    """Ką atspausdins?"""

    def filtruok_skaicius( sar ):
        for x in sar:
            if x % _dalmuo == 0: # jeigu dalijasi be liekanos
                print (x)

    filtruok_skaicius( _sar )
fun_loop_print_filter_remainder()

def fun_loop_print_sum_filter(_sar=[4, 2, 2, 5, 4, 5], _k=3):
    """Ką atspausdins?"""

    def filtruok_skaicius( sar ):
        suma = 0
        for x in sar:
            suma = suma+x
            if suma / x > _k: 
                print (x)

    filtruok_skaicius( _sar )
fun_loop_print_sum_filter()

####### lists #########
